<?php
/* 不带登陆的公用的控制器
* @Author: Jerry-chen
* @Date:   2014-07-06 17:57:13
* @Last Modified time: 2014-07-24 18:39:40
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/
class PublicControl extends Control
{
	public function __init(){
		//========================================导航条数据==============================================
        $cateData = K('Category')->get_all(array('pid'=>0));
        // p($cateData);
        foreach ($cateData as $k => $v) {
            // 通过父级找出子级 
            $cateData[$k]['son']=K('Category')->get_all(array('pid'=>$v['cateid']));;
            //如果SON里面没有数据给它个0方便前端判断
            if( $cateData[$k]['son']==''){
                 $cateData[$k]['son']=array(
                    '0');
            }
            // p($v['son']);
            // break;
        }
        // p($cateData);
        $this->assign('cateData',$cateData);
        //购物车
        //检测用户是否登录,
		if(!isset($_SESSION['username']) || !isset($_SESSION['uid'])){
			//不登陆时的SHOPCAR数量
			$shopcarnumber = count(session('shopcar'));
			$this->assign('shopcarnumber',$shopcarnumber);
		}else{
			//登陆时的SHOPCAR数量
			 $shopcarnumber= K('Shopcar')->get_all(array('uid'=>$_SESSION['uid']));
			 $shopcarnumber = count($shopcarnumber);
			 // p($shopcarnumber);
			 $this->assign('shopcarnumber',$shopcarnumber);
		}




	}
	
}

